
package dao;

import java.sql.Connection;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import vo.LocacaoVO;
import vo.ReservaVO;
import vo.PessoaVO;

public class LocacaoDAO {
     
    public static void insertLocacao(LocacaoVO locacao){
        Connection con = ConnectionFactory.getConnection();
        
        try{
            String query = "INSERT INTO Locacao VALUES(?,?,?,?,?,?,?)";
            PreparedStatement stmt = con.prepareStatement(query);
            
            stmt.setInt(1,locacao.getId());
            stmt.setFloat(2,locacao.getOrcamentoPre());
            stmt.setString(3,locacao.getPlacaVeiculo());
            stmt.setString(4,locacao.getCpfFuncionario());
            stmt.setString(5,locacao.getCpfCliente()); 
            stmt.setDate (6,null);
            stmt.setFloat(7,0);
        
            stmt.executeUpdate();           
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }

    public static boolean locacaoExiste(int ID) {
        Connection con = ConnectionFactory.getConnection();
        int id;
        try{
            String query = "Select * from locacao where id= ?";
            PreparedStatement stmt= con.prepareStatement(query);
            stmt.setInt(1,ID);

            ResultSet res = stmt.executeQuery();
            while(res.next()){
            id=res.getInt(1);
            
            if(ID==id)
            {            
            return true;
            }}

        }catch(Exception e){

        }  
       return false;          
    }

    public static void insert_Possui_Opcional(String opc, String loc) {
        Connection con = ConnectionFactory.getConnection();
        int a = Integer.parseInt(loc);
        try{
            String query = "INSERT INTO Possui_Opcional VALUES(?,?)";
            PreparedStatement stmt = con.prepareStatement(query);
            stmt.setInt(1,a);           
            stmt.setString(2,opc);


        
            stmt.executeUpdate();           
        }
        catch(Exception e){
            e.printStackTrace();
        }        
    }
    
}
